function formatNumber(n) {
    n = n.toString();
    return n[1] ? n : '0' + n
}

Vue.filter('formatTime',function (number,format) {
    let formateArr  = ['Y','M','D','h','m','s'];
    let returnArr   = [];

    let date = new Date(number);
    returnArr.push(date.getFullYear())//在字符数组的末尾插入一个元素
    returnArr.push(formatNumber(date.getMonth() + 1));
    returnArr.push(formatNumber(date.getDate()));

    returnArr.push(formatNumber(date.getHours()));
    returnArr.push(formatNumber(date.getMinutes()));
    returnArr.push(formatNumber(date.getSeconds()));

    for (let i in returnArr)
    {
        format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
});

Vue.component('page-div',{
    props:{
        page:{}

        },
    data(){
        return{

        }
    },
    template:`
        <div class="clearfix">
              <div style="float: left;">
                <div style="padding-top:5px;">
                  <span class="badge badge-info">
                    当前第 {{page.pageNum}} 页 / {{page.pages}} 页，共 {{page.total}} 条数据
                  </span>
                </div>
              </div>
              <div>
                <div class="pagination no-margin pull-right clearfix">
                  <li class="prev"><a href="javascript:void(0);" @click="$emit('select-page'),1">首页</a></li>
                  <li v-if="page.hasPreviousPage" class="prev"><a href="javascript:void(0);" @click="selectPage(page.pageNum-1)">上一页</a></li>
                  <li v-else class="prev disabled"><a href="javascript:void(0);" onclick="">上一页</a></li>
                  <template v-for="pageIndex in page.navigatepageNums">
                    <li v-if="pageIndex==page.pageNum" class="active"><a href="javascript:void(0);" onclick="">{{pageIndex}}</a></li>
                    <li v-else><a href="javascript:void(0);" @click="selectPage(pageIndex)">{{pageIndex}}</a></li>
                  </template>
                  <li v-if="page.hasNextPage" class="next"><a href="javascript:void(0);" @click="selectPage(page.pageNum+1)">下一页</a></li>
                  <li v-else class="next disabled"><a href="javascript:void(0);" onclick="">下一页</a></li>
                  <li class="next"><a href="javascript:void(0);" @click="$emit('select-page'),page.pages">尾页</a></li>
                </div>
              </div>
            </div>
    `
});
